home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / history.test < prev    next >
Text File  |  1992-11-06  |  13KB  |  390 lines

  1. # Commands covered:  history
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /sprite/src/lib/tcl/tests/RCS/history.test,v 1.7 91/09/09 11:50:13 ouster Exp $ (Berkeley)
  17.   
  18. if {[info commands history] == ""} {
  19.     puts stdout "This version of Tcl was built without the history command;\n"
  20.     puts stdout "history tests will be skipped.\n"
  21.     return
  22. }
  23.  
  24. if {[string compare test [info procs test]] == 1} then {source defs}
  25.  
  26. set num [history nextid]
  27. history keep 3
  28. history add {set a 12345}
  29. history add {set b [format {A test %s} string]}
  30. history add {Another test}
  31.  
  32. # "history event"
  33.  
  34. test history-1.1 {event option} {history event -1} \
  35.     {set b [format {A test %s} string]}
  36. test history-1.2 {event option} {history event $num} \
  37.     {set a 12345}
  38. test history-1.3 {event option} {history event [expr $num+2]} \
  39.     {Another test}
  40. test history-1.4 {event option} {history event set} \
  41.     {set b [format {A test %s} string]}
  42. test history-1.5 {event option} {history e "* a*"} \
  43.     {set a 12345}
  44. test history-1.6 {event option} {catch {history event *gorp} msg} 1
  45. test history-1.7 {event option} {
  46.     catch {history event *gorp} msg
  47.     set msg
  48. } {no event matches "*gorp"}
  49. test history-1.8 {event option} {history event} \
  50.     {set b [format {A test %s} string]}
  51. test history-1.9 {event option} {catch {history event 123 456} msg} 1
  52. test history-1.10 {event option} {
  53.     catch {history event 123 456} msg
  54.     set msg
  55. } {wrong # args: should be "history event ?event?"}
  56.  
  57. # "history redo"
  58.  
  59. set a 0
  60. history redo -2
  61. test history-2.1 {redo option} {set a} 12345
  62. set b 0
  63. history redo
  64. test history-2.2 {redo option} {set b} {A test string}
  65. test history-2.3 {redo option} {catch {history redo -3 -4}} 1
  66. test history-2.4 {redo option} {
  67.     catch {history redo -3 -4} msg
  68.     set msg
  69. } {wrong # args: should be "history redo ?event?"}
  70.  
  71. # "history add"
  72.  
  73. history add "set a 444" exec
  74. test history-3.1 {add option} {set a} 444
  75. test history-3.2 {add option} {catch {history add "set a 444" execGorp}} 1
  76. test history-3.3 {add option} {
  77.     catch {history add "set a 444" execGorp} msg
  78.     set msg
  79. } {bad argument "execGorp": should be "exec"}
  80. test history-3.4 {add option} {catch {history add "set a 444" a} msg} 1
  81. test history-3.5 {add option} {
  82.     catch {history add "set a 444" a} msg
  83.     set msg
  84. } {bad argument "a": should be "exec"}
  85. history add "set a 555" e
  86. test history-3.6 {add option} {set a} 555
  87. history add "set a 666"
  88. test history-3.7 {add option} {set a} 555
  89. test history-3.8 {add option} {catch {history add "set a 666" e f} msg} 1
  90. test history-3.9 {add option} {
  91.     catch {history add "set a 666" e f} msg
  92.     set msg
  93. } {wrong # args: should be "history add event ?exec?"}
  94.  
  95. # "history change"
  96.  
  97. history change "A test value"
  98. test history-4.1 {change option} {history event [expr {[history n]-1}]} \
  99.     "A test value"
  100. history c "Another test" -1
  101. test history-4.2 {change option} {history e} "Another test"
  102. test history-4.3 {change option} {history event [expr {[history n]-1}]} \
  103.     "A test value"
  104. test history-4.4 {change option} {catch {history change Foo 4 10}} 1
  105. test history-4.5 {change option} {
  106.     catch {history change Foo 4 10} msg
  107.     set msg
  108. } {wrong # args: should be "history change newValue ?event?"}
  109. test history-4.6 {change option} {
  110.     catch {history change Foo [expr {[history n]-4}]}
  111. } 1
  112. test history-4.7 {change option} {
  113.     catch {history change Foo [expr {[history n]-4}]}
  114.     set msg
  115. } {wrong # args: should be "history change newValue ?event?"}
  116.  
  117. # "history info"
  118.  
  119. set num [history n]
  120. history add set\ a\ {b\nc\ d\ e}
  121. history add {set b 1234}
  122. history add set\ c\ {a\nb\nc}
  123. test history-5.1 {info option} {history info} [format {%6d  set a {b
  124.     c d e}
  125. %6d  set b 1234
  126. %6d  set c {a
  127.     b
  128.     c}} $num [expr $num+1] [expr $num+2]]
  129. test history-5.2 {info option} {history i 2} [format {%6d  set b 1234
  130. %6d  set c {a
  131.     b
  132.     c}} [expr $num+1] [expr $num+2]]
  133. test history-5.3 {info option} {catch {history i 2 3}} 1
  134. test history-5.4 {info option} {
  135.     catch {history i 2 3} msg
  136.     set msg
  137. } {wrong # args: should be "history info ?count?"}
  138. test history-5.5 {info option} {history} [format {%6d  set a {b
  139.     c d e}
  140. %6d  set b 1234
  141. %6d  set c {a
  142.     b
  143.     c}} $num [expr $num+1] [expr $num+2]]
  144.  
  145. # "history keep"
  146.  
  147. history add "foo1"
  148. history add "foo2"
  149. history add "foo3"
  150. history keep 2
  151. test history-6.1 {keep option} {history event [expr [history n]-1]} foo3
  152. test history-6.2 {keep option} {history event -1} foo2
  153. test history-6.3 {keep option} {catch {history event -3}} 1
  154. test history-6.4 {keep option} {
  155.     catch {history event -3} msg
  156.     set msg
  157. } {event "-3" is too far in the past}
  158. history k 5
  159. test history-6.5 {keep option} {history event -1} foo2
  160. test history-6.6 {keep option} {history event -2} {}
  161. test history-6.7 {keep option} {history event -3} {}
  162. test history-6.8 {keep option} {history event -4} {}
  163. test history-6.9 {keep option} {catch {history event -5}} 1
  164. test history-6.10 {keep option} {catch {history keep 4 6}} 1
  165. test history-6.11 {keep option} {
  166.     catch {history keep 4 6} msg
  167.     set msg
  168. } {wrong # args: should be "history keep number"}
  169. test history-6.12 {keep option} {catch {history keep}} 1
  170. test history-6.13 {keep option} {
  171.     catch {history keep} msg
  172.     set msg
  173. } {wrong # args: should be "history keep number"}
  174. test history-6.14 {keep option} {catch {history keep -3}} 1
  175. test history-6.15 {keep option} {
  176.     catch {history keep -3} msg
  177.     set msg
  178. } {illegal keep count "-3"}
  179.  
  180. # "history nextid"
  181.  
  182. set num [history n]
  183. history add "Testing"
  184. history add "Testing2"
  185. test history-7.1 {nextid option} {history event} "Testing"
  186. test history-7.2 {nextid option} {history next} [expr $num+2]
  187. test history-7.3 {nextid option} {catch {history nextid garbage}} 1
  188. test history-7.4 {nextid option} {
  189.     catch {history nextid garbage} msg
  190.     set msg
  191. } {wrong # args: should be "history nextid"}
  192.  
  193. # "history substitute"
  194.  
  195. test history-8.1 {substitute option} {
  196.     history add "set a {test foo test b c test}"
  197.     history add "Test command 2"
  198.     set a 0
  199.     history substitute foo bar -1
  200.     set a
  201. } {test bar test b c test}
  202. test history-8.2 {substitute option} {
  203.     history add "set a {test foo test b c test}"
  204.     history add "Test command 2"
  205.     set a 0
  206.     history substitute test gorp
  207.     set a
  208. } {gorp foo gorp b c gorp}
  209. test history-8.3 {substitute option} {
  210.     history add "set a {test foo test b c test}"
  211.     history add "Test command 2"
  212.     set a 0
  213.     history sub " te" to
  214.     set a
  215. } {test footost b ctost}
  216. test history-8.4 {substitute option} {catch {history sub xxx yyy}} 1
  217. test history-8.5 {substitute option} {
  218.     catch {history sub xxx yyy} msg
  219.     set msg
  220. } {"xxx" doesn't appear in event}
  221. test history-8.6 {substitute option} {catch {history s a b -10}} 1
  222. test history-8.7 {substitute option} {
  223.     catch {history s a b -10} msg
  224.     set msg
  225. } {event "-10" is too far in the past}
  226. test history-8.8 {substitute option} {catch {history s a b -1 20}} 1
  227. test history-8.9 {substitute option} {
  228.     catch {history s a b -1 20} msg
  229.     set msg
  230. } {wrong # args: should be "history substitute old new ?event?"}
  231.  
  232. # "history words"
  233.  
  234. test history-9.1 {words option} {
  235.     history add {word0 word1 word2 a b c word6}
  236.     history add foo
  237.     history words 0-$
  238. } {word0 word1 word2 a b c word6}
  239. test history-9.2 {words option} {
  240.     history add {word0 word1 word2 a b c word6}
  241.     history add foo
  242.     history w 2 -1
  243. } word2
  244. test history-9.3 {words option} {
  245.     history add {word0 word1 word2 a b c word6}
  246.     history add foo
  247.     history wo $
  248. } word6
  249. test history-9.4 {words option} {catch {history w 1--1} msg} 1
  250. test history-9.5 {words option} {
  251.     catch {history w 1--1} msg
  252.     set msg
  253. } {bad word selector "1--1":  should be num-num or pattern}
  254. test history-9.6 {words option} {
  255.     history add {word0 word1 word2 a b c word6}
  256.     history add foo
  257.     history w w
  258. } {}
  259. test history-9.7 {words option} {
  260.     history add {word0 word1 word2 a b c word6}
  261.     history add foo
  262.     history w *2
  263. } word2
  264. test history-9.8 {words option} {
  265.     history add {word0 word1 word2 a b c word6}
  266.     history add foo
  267.     history w *or*
  268. } {word0 word1 word2 word6}
  269. test history-9.9 {words option} {catch {history words 10}} 1
  270. test history-9.10 {words option} {
  271.     catch {history words 10} msg
  272.     set msg
  273. } {word selector "10" specified non-existent words}
  274. test history-9.11 {words option} {catch {history words 1 -1 20}} 1
  275. test history-9.12 {words option} {
  276.     catch {history words 1 -1 20} msg
  277.     set msg
  278. } {wrong # args: should be "history words num-num/pat ?event?"}
  279.  
  280. # history revision
  281.  
  282. test history-10.1 {history revision} {
  283.     set a 0
  284.     history a {set a 12345}
  285.     history a {set a [history e]} exec
  286.     set a
  287. } {set a 12345}
  288. test history-10.2 {history revision} {
  289.     set a 0
  290.     history a {set a 12345}
  291.     history a {set a [history e]} exec
  292.     history a foo
  293.     history ev -1
  294. } {set a {set a 12345}}
  295. test history-10.3 {history revision} {
  296.     set a 0
  297.     history a {set a 12345}
  298.     history a {set a [history e]} exec
  299.     history a foo
  300.     history a {history r -2} exec
  301.     history a {set a 12345}
  302.     history ev -1
  303. } {set a {set a 12345}}
  304. test history-10.4 {history revision} {
  305.     history a {set a 12345}
  306.     history a {history s 123 999} exec
  307.     history a foo
  308.     history ev -1
  309. } {set a 99945}
  310. test history-10.5 {history revision} {
  311.     history add {word0 word1 word2 a b c word6}
  312.     history add {set [history w 3] [list [history w 0] [history w {[ab]}]]} exec
  313.     set a
  314. } {word0 {a b}}
  315. test history-10.6 {history revision} {
  316.     history add {word0 word1 word2 a b c word6}
  317.     history add {set [history w 3] [list [history w 0] [history w {[ab]}]]} exec
  318.     history add foo
  319.     history ev
  320. } {set a [list word0 {a b}]}
  321. test history-10.7 {history revision} {
  322.     history add {word0 word1 word2 a b c word6}
  323.     history add {set [history w 3] [list [history w 0] [history w {[ab]}]]} exec
  324.     history add {format b}
  325.     history add {word0 word1 word2 a b c word6}
  326.     set a 0
  327.     history add {set [history subs b a -2] [list abc [history r -2] [history w 1-3]]} exec
  328.     history add foo
  329.     history ev
  330. } {set [format a] [list abc [format b] {word1 word2 a}]}
  331. test history-10.8 {history revision} {
  332.     history add {set a 12345}
  333.     concat a b c
  334.     history add {history redo; set b 44} exec
  335.     history add foo
  336.     history ev
  337. } {set a 12345; set b 44}
  338. test history-10.9 {history revision} {
  339.     history add {set a 12345}
  340.     history add {history redo; history change "A simple test"; history subs 45 xx} exec
  341.     set a
  342. } 123xx
  343. test history-10.10 {history revision} {
  344.     history add {set a 12345}
  345.     history add {history redo; history change "A simple test"; history subs 45 xx} exec
  346.     history add foo
  347.     history e
  348. } {A simple test}
  349. test history-10.11 {history revision} {
  350.     history add {word0 word1 $ a b c word6}
  351.     history add {set a [history w 4-[history word 2]]} exec
  352.     set a
  353. } {b c word6}
  354. test history-10.12 {history revision} {
  355.     history add {word0 word1 $ a b c word6}
  356.     history add {set a [history w 4-[history word 2]]} exec
  357.     history add foo
  358.     history e
  359. } {set a {b c word6}}
  360. test history-10.13 {history revision} {
  361.     history add {history word 0} exec
  362.     history add foo
  363.     history e
  364. } {history word 0}
  365. test history-10.14 {history revision} {
  366.     history add {set a [history word 0; format c]} exec
  367.     history add foo
  368.     history e
  369. } {set a [history word 0; format c]}
  370. test history-10.15 {history revision even when nested} {
  371.     proc x {a b} {history word $a $b}
  372.     history add {word1 word2 word3 word4}
  373.     history add {set a [x 1-3 -1]} exec
  374.     history add foo
  375.     history e
  376. } {set a {word2 word3 word4}}
  377. test history-10.16 {disable history revision in nested history evals} {
  378.     history add {word1 word2 word3 word4}
  379.     history add {set a [history words 0]; history add foo; set a [history words 0]} exec
  380.     history e
  381. } {set a word1; history add foo; set a [history words 0]}
  382.  
  383. # miscellaneous
  384.  
  385. test history-11.1 {miscellaneous} {catch {history gorp} msg} 1
  386. test history-11.2 {miscellaneous} {
  387.     catch {history gorp} msg
  388.     set msg
  389. } {bad option "gorp": must be add, change, event, info, keep, nextid, redo, substitute, or words}
  390.